<template>
  <div id="app">
    <img src="./assets/logo.png">
    <h1>我是网站标题</h1>
    <!-- <router-view/> 根据标签路径动态渲染组件 在上面渲染到上面,在下面渲染到下面 -->
    <!--    <router-view/>-->
    <!-- keep-alive 会缓存 -->
    <!-- exclude 不会被缓存,组件会重新创建 后面根的是组件的name 字符串和正则表达式匹配 -->
    <!-- include 会被缓存,组件会重新创建 后面根的是组件的name 字符串和正则表达式匹配 -->
    <keep-alive exclude="Profile,User">
      <router-view/>
    </keep-alive>
    <!-- router-link to="/home" 页面启用路由 to用于跳转 -->
    <!-- tag 可以指定 <router-link>之后渲染成什么组件,比如tag="button",tag="li" -->
    <!-- replace 禁止浏览器网页的前进和后退 -->
    <!-- active-class="active" 修改点中后的样式状态 默认router-link-active -->
    <!--    <router-link to="/home" tag="button" replace>首页</router-link>-->
    <!--    <router-link to="/about" tag="li" replace>关于</router-link>-->
    <!--    <button @click="homeClick">首页</button>-->
    <!--    <button @click="aboutClick">关于</button>-->
    <router-link to="/home">首页</router-link>
    <router-link to="/about">关于</router-link>
    <!-- 前面加v-bind:拼接data的数据 -->
    <!--    <router-link v-bind:to="'/user/' + userId">用户</router-link>-->
    <!-- query 传参,get请求拼接 -->
    <!--    <router-link :to="{path: '/profile', query: {name: 'why', age: 18}}">档案</router-link>-->
    <button @click="userClick">用户</button>
    <button @click="profileClick">档案</button>
    <h2>版权信息</h2>
  </div>
</template>

<script>
  export default {
    name: 'App',
    data() {
      return {
        userId: "zhangsan"
      }
    },
    methods: {
      homeClick() {
        // 通过代码方式修改路由 vue-router
        // this.$router.push("/home");
        this.$router.replace("/home");
        console.log("homeClick");
      },
      aboutClick() {
        // this.$router.push("/about");
        this.$router.replace("/about");
        console.log("aboutClick");
      },
      userClick() {
        this.$router.push("/user/" + this.userId)
      },
      profileClick() {
        this.$router.push({
          path: "/profile/",
          query: {
            name: "why",
            age: 18
          }
        })
      }
    }
  }
</script>

<style>
  #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
  }

  .router-link-active {
    color: red;
  }

  .active {
    color: red;
  }
</style>
